<?php
/**
 * Author Yulin
 * Email  dwzhanglong@126.com
 * Date   2017-6-3
 * Func   注册会员
 */
defined('IN_YuLin') || exit('NO PERMIT!');

$table = Table('user');
$utable = Table('user_info');
$stable = Table('user_status');
$ltable = Table('user_infolog');

if($a == 'infolog')	//	记录
{
	
}
else
{
	$statuss = ['禁用','启用'];
	$orderbys = ['dtdesc'=>'注册时间倒序','dtasc'=>'注册时间升序','moneydesc'=>'余额倒序','moneyasc'=>'余额升序'];
	$orderbys2 = ['dtdesc'=>'t.id DESC','dtasc'=>'t.id','rebatedesc'=>'s.rebate DESC','rebateasc'=>'s.rebate','moneydesc'=>'t.money DESC','moneyasc'=>'t.money'];
	
	$data  = array();
	$where = ' FROM '.$table.' t LEFT JOIN '.$utable.' u ON t.id = u.uid LEFT JOIN '.$stable.' s ON t.id = s.uid WHERE 1 ';
    $where .= ' AND s.upuid = '.$_uid;
	
    $status = intval($_GET['status']);
	$status && $where .= ' AND t.status = '.($status > 0 ? $status : 0);
	
	//	时间
	$dt1 = NoBadStr($_GET['dt1']);
	$dt1 && $where .= ' AND t.reg_time >= '.strtotime($dt1);
	$dt2 = NoBadStr($_GET['dt2']);
	$dt2 && $where .= ' AND t.reg_time <= '.strtotime($dt2);
    
	$title = NoBadStr($_GET['title']);
	$title && $where .= ' AND (t.username LIKE \'%'.$title.'%\' OR u.nickname LIKE \''.$title.'\') ';
	
	//	排序
	$orderby = NoBadStr($_GET['orderby']);
	!array_key_exists($orderby,$orderbys) && $orderby = 'dtdesc';

	$tmp = $db->getrow('SELECT COUNT(1) AS p '.$where);
	if($tmp['p'])
	{
		$page = max(1,intval($_GET['page']));
		$size = 20;
		$limit = $_GET['export'] ? '' : ' LIMIT '.($page - 1) * $size.','.$size;
		
		$url = '?m='.$m.'&c='.$c.'&a='.$a.'&title='.$title.'&status='.$status.'&upuid='.$upuid.'&gid='.$gid.'&dt1='.$dt1.'&dt2='.$dt2.'&orderby='.$orderby;
		
		$data = $db->getall('SELECT t.*,u.*,s.* '.$where.' ORDER BY '.$orderbys2[$orderby].$limit);
		
		$multi = Multi($url,$page,$tmp['p'],$size);
	}
	
	$tpl->display('user/index');
}